// pages/quan/quan.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    state:0,
    loadmore: 'block',
    nodata: 'none',
    nomore: 'none',
    page: 1,
    list: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.Find_MyQuan();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  Find_MyQuan: function () {
    var that = this;
    var data = {};
    data.act = "Find_MyQuan";
    data.state=this.data.state;
    data.page = that.data.page;
    app.Ajax(data, function (json) {
      var pagecount = Math.floor(Math.abs(json.count - 1) / json.pagesize) + 1;
      if (data.page > pagecount) { return; }
      that.setData({ list: that.data.list.concat(json.data), page: data.page + 1 });
      if (that.data.list.length == 0) {
        that.setData({ loadmore: 'none', nodata: 'block', nomore: 'none' });
      }
      else if (pagecount == 1) {
        that.setData({ loadmore: 'none', nodata: 'none', nomore: 'none' });
      }
      else if (data.page < pagecount) {
        that.setData({ loadmore: 'block', nodata: 'none', nomore: 'none' });
      } else if (data.page == pagecount) {
        that.setData({ loadmore: 'none', nodata: 'none', nomore: 'block' });
      }
      wx.stopPullDownRefresh();
    });
  },
  openProduct:function(){
    wx.navigateTo({
      url: '/pages/product/product?order=allrank'
    })
  },
  changetab: function (e) {
    var state = e.currentTarget.dataset.state;
    this.setData({ list: [], page: 1, loadmore: 'block', nodata: 'none', nomore: 'none', state: state });
    this.Find_MyQuan();
  }
})